//
//  FCIMainViewController.swift
//  YQInformation
//
//  Created by Max on 2017/11/2.
//  Copyright © 2017年 com.vector. All rights reserved.
//

import UIKit

class FCIMainViewController: FQIViewController , UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var scrView: UIScrollView!
    @IBOutlet weak var backView: UIView!
    @IBOutlet weak var tableView: UITableView!
    
   
    override func viewDidLoad() {
        super.viewDidLoad()

        if self.navigationItem.leftBarButtonItem != nil {
            let btn = UIButton(type: UIButtonType.custom)
            self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn)
        }
    
 
        scrView.showsVerticalScrollIndicator = false
        self.navigationController?.navigationBar
            .setBackgroundImage(UIImage(named: "29"), for: .default)
        
        let button2 = UIButton(frame:CGRect(x:0, y:0, width:40, height:44))
        button2.setImage(UIImage(named:"31"), for: .normal)
        button2.addTarget(self, action: #selector(FCIMainViewController.messageAction), for: .touchUpInside)
        let barButton2 = UIBarButtonItem(customView: button2)
        self.navigationItem.rightBarButtonItems = [barButton2]
        
        let button = UIButton(frame:CGRect(x: 0, y: 0, width: 110, height: 110))
        button.setImage(UIImage(named:"32"), for: .normal)
        button.addTarget(self,action:#selector(FCIMainViewController.wantBoroowAction),for:.touchUpInside)
        self.navigationItem.titleView = button
        
        tableView.tableFooterView = UIView()
        tableView.separatorStyle = UITableViewCellSeparatorStyle.none
        
        
    }

    
    
    override func viewWillAppear(_ animated: Bool) {
        
        super.viewWillAppear(animated)
        
        self.navigationController?.navigationBar
            .setBackgroundImage(UIImage(named: "29"), for: .default)
        
        
        
    }
    
    
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return 5
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = FQIMainCell()
        
        cell = (tableView.dequeueReusableCell(withIdentifier: FQIMainCell.name,for: indexPath) as? FQIMainCell)!
    
        return cell
        
    }
    
    
    // tableView AutomaticDimension
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        
        return UITableViewAutomaticDimension
    }
    
    func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
        
        return UITableViewAutomaticDimension
    }

    
      func wantBoroowAction() {
        let alertController = UIAlertController(title: "请选择借款金额", message: nil, preferredStyle: UIAlertControllerStyle.actionSheet)
        
        let cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.cancel, handler: nil)
      
        let deleteAction = UIAlertAction(title: "2000", style: UIAlertActionStyle.default, handler: { (UIAlertAction) -> Void in
          
            
            
        
        })
        
        
        
        let archiveAction = UIAlertAction(title: "2000~5000", style: UIAlertActionStyle.default,  handler: { (UIAlertAction) -> Void in
            
            
            
            
        })
        let archiveAction1 = UIAlertAction(title: "5000~10000", style: UIAlertActionStyle.default,  handler: { (UIAlertAction) -> Void in
            
            
            
            
        })

        
        let archiveAction2 = UIAlertAction(title: "10000以上", style: UIAlertActionStyle.default,  handler: { (UIAlertAction) -> Void in
            
            
            
            
        })
      
        
        alertController.addAction(cancelAction)
        alertController.addAction(deleteAction)
        alertController.addAction(archiveAction)
        alertController.addAction(archiveAction1)
        alertController.addAction(archiveAction2)
        
        
        self.present(alertController, animated: true, completion: nil)
        

        
    }
    
    
    @IBAction func fiveAction(_ sender: Any) {
    
    
    }
    
    
    @IBAction func sixAction(_ sender: Any) {
    
    
    }
    
    
    
    @IBAction func sevenAction(_ sender: Any) {
    
    
    }
    
    
    @IBAction func eightAction(_ sender: Any) {
  
    
    }
    
    
    @IBAction func oneAction(_ sender: Any) {
    
    
    }
    
    
    @IBAction func twoAction(_ sender: Any) {
    
        
    }

    
    @IBAction func threeAction(_ sender: Any) {
    
        
    }
    
   
    @IBAction func fourAction(_ sender: Any) {
    
        
    
    }
   
    
    
    
    func messageAction() {
    
        if let v = FQIMessageViewController.create() as? FQIMessageViewController {
            v.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(v, animated: true)
        }
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
}
